<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
function tipOpen(content,num,productStatus) {
  $(".tipright p").text(content);
  $("#tip").fadeIn(200);
  $("#productId").val(num);
  $("#productStatus").val(productStatus);
}
function tipClose() {
  $("#tip").fadeOut(200);
  var productId=$("#productId").val();
  var productStatus=$("#productStatus").val();
  location.href="/erp/purchase/product/updateZt?productId="+productId+"&productStatus="+productStatus;
}

function tipClose2() {
  $("#tip").fadeOut(200);
}

</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="/erp/purchase/product/cplist" method="post" id="cpfrom">
    <input type="hidden" name="pageno" value="1" id="pageno"/>
    <ul class="tools">
      <li> 品牌名称:
        <select name="brandBId" onchange="getType(this.value)">
          <option value="0">请选择</option>
          <option th:each="b:${session.brands}" th:text="${b.brandName}" th:value="${b.brandId}"
                  th:selected="${b.brandId==pro.brandBId}"
          ></option>
        </select>
      </li>
      <li> 商品类型:
        <select name="typeId" >
          <option value="0">请选择</option>
        </select>
      </li>
      <li> 商品型号:
        <input type="text"  name="productModel" th:value="${pro.productModel}"/>
      </li>
      <li> 状态：
        <select name="productStatus">
          <option value="0">请选择</option>
          <option value="1" th:selected="${pro.productStatus==1}?'true':'false'">可用</option>
          <option value="2" th:selected="${pro.productStatus==2}?'true':'false'">不可用</option>
        </select>
      </li>
      <li class="subBut" onclick="goPage(1)"><img src="../../images/t06.png" />查询</li>
      <li class="subBut" onclick="window.location.href='/erp/purchase/product/addPro'"><img src="../../images/t01.png" />添加</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>品牌名称</th>
          <th>商品类型</th>
          <th>商品型号</th>
          <th>单位</th>
          <th>状态</th>
          <th>创建时间</th>
          <th>创建人</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="p:${Cpage.list}">
          <td th:text="${p.productId}">1</td>
          <td th:text="${p.types.cBrand.brandName}">联想</td>
          <td th:text="${p.types.typeName}">笔记本</td>
          <td th:text="${p.productModel}">X260</td>
          <td th:text="${p.productUnit}">台</td>
          <td th:text="${p.productStatus==1?'可用':'不可用'}">可用</td>
          <td th:text="${#dates.format(p.createTime,'yyyy-MM-dd HH:mm:ss')}">2013-09-09 15:05:05</td>
          <td th:text="${p.users.uname}">管理员</td>
          <td>
            <a th:href="@{'/purchase/product/goupdate/'+${p.productId}}" class="tablelink">修改</a>
            <input type="hidden" id="productId"/>
            <input type="hidden" id="productStatus">
            <a href="javascript:void(0)" th:if="${p.productStatus==1}" class="tablelink" th:onclick="@{'tipOpen(\'是否确认注销此条信息？\','+${p.productId}+','+2+')'}">注销</a>
            <a href="javascript:void(0)" th:if="${p.productStatus==2}" class="tablelink" th:onclick="@{'tipOpen(\'是否确认恢复此条信息？\','+${p.productId}+','+1+')'}">恢复</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${Cpage.total}"></i>条记录，当前显示第&nbsp;<i class="blue" th:text="${Cpage.pageNum}">2&nbsp;</i>页</div>
      <ul class="paginList">
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="goPage([[${Cpage.isFirstPage?1:Cpage.pageNum-1}]])">
            <span th:class="${Cpage.isFirstPage?'pagepre':'pagenxt roate'}"></span>
          </a>
        </li>
        <li th:class="${page==Cpage.pageNum?'paginItem current':'paginItem'}"
            th:each="page : ${Cpage.navigatepageNums}">
          <a href="javascript:;"  th:text="${page}" th:onclick="goPage([[${page}]])">1</a>
        </li>
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="goPage([[${Cpage.isLastPage?Cpage.pages:Cpage.pageNum+1}]])">
            <span th:class="${Cpage.isLastPage?'pagepre roate':'pagenxt'}"></span>
          </a>
        </li>
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose2()"></a></div>
    <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="tipClose()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose2()" />
    </div>
  </div>
</div>
<script th:inline="javascript">
  $(function () {
    var num=$("select[name=brandBId]").val();
    getType(num);
  });

	$('.tablelist tbody tr:odd').addClass('odd');

    function goPage(num) {
      // alert(num);
      $("#pageno").val(num);
      $("#cpfrom").submit();
    }



    function getType(num) {
      $.get("/erp/ajaxType",{"bid":num},function (data) {
        console.log(data);
         $("select[name=typeId]").html("");
         var options="<option value=''>请选择</option>";
        var t=[[${pro.typeId}]];
        $.each(data,function (i,e) {
          if(e.typeId==t){
            options+="<option value='"+e.typeId+"' selected='selected'>"+e.typeName+"</option>";
          }else{
            options+="<option value='"+e.typeId+"'>"+e.typeName+"</option>";
          }

         });
         $("select[name=typeId]").append(options);
      },"json");
    }

</script>
</body>
</html>
